package com.mui.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.mui.dao.MenuDao;
import com.mui.entity.MenuInfo;
import com.mui.util.ObjectOpUtil;

@Repository
public class MenuDaoImpl implements MenuDao {
	
	@Autowired  
	private JdbcTemplate jdbcTemplate;  

	@Override
	public MenuInfo read(String name) {
		String sql = "select * from menu where name = ? and showmenu = 1";
		Map<String, Object> map = jdbcTemplate.queryForMap(sql, new Object[] {name});
		MenuInfo menuInfo = new MenuInfo();
				
		menuInfo = (MenuInfo)ObjectOpUtil.setObject(menuInfo, map);
		
		return menuInfo;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<MenuInfo> read() {
		String sql = "select * from menu where showmenu = 1";
		List<Map<String, Object>>  listMap = jdbcTemplate.queryForList(sql);
		MenuInfo menu = new MenuInfo();
		List<MenuInfo> menuList = (List<MenuInfo>)ObjectOpUtil.setObject(menu, listMap);
		return menuList;
	}  

	@Override
	public MenuInfo read(int id) {
		return null;
	}

	@Override
	public String updata(MenuInfo menu) {
		//String sql = "insert into user (username,age) values ()";
		return null;
	}
	
}
